//
//  LBTabBarViewController.m
//  LBWeibo
//
//  Created by lin on 15/7/6.
//  Copyright (c) 2015年 lin. All rights reserved.
//

#import "LBTabBarViewController.h"
#import "LBTabBar.h"
#import "LBNavViewController.h"
#import "HomeTableViewController.h"
#import "ComposeViewController.h"
#define COLOR_RANDOM  [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1]

@interface LBTabBarViewController ()<LBTabBarDelegate>
@property(nonatomic,weak)LBTabBar *mainTabBar;
@property(nonatomic,strong)HomeTableViewController *homeVC;
@end

@implementation LBTabBarViewController
-(HomeTableViewController *)homeVC{
    if (!_homeVC) {
        _homeVC =[[HomeTableViewController alloc] init];
    }
    return _homeVC;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initChildVC];
    [self setUpTabBar];
    //替换原有的tabbar
    
  
    
    
}


-(void)initChildVC{
    HomeTableViewController *homeTV = [[HomeTableViewController alloc] initWithStyle:UITableViewStylePlain];
    [self addChildViewController:homeTV title:@"首页" img:[UIImage imageNamed:@"tabbar_home"] selectedImg:[UIImage imageNamed:@"tabbar_home_selected"]];
    
    UIViewController *messageVC = [[UIViewController alloc] init];
    [self addChildViewController:messageVC title:@"消息" img:[UIImage imageNamed:@"tabbar_message_center"] selectedImg:[UIImage imageNamed:@"tabbar_message_center_selected"]];
    
    UIViewController *discoveryVC = [[UIViewController alloc] init];
    discoveryVC.view.backgroundColor = COLOR_RANDOM;
    [self addChildViewController:discoveryVC title:@"发现" img:[UIImage imageNamed:@"tabbar_discover"] selectedImg:[UIImage imageNamed:@"tabbar_discover_selected"]];
    
    UIViewController *profileVC = [[UIViewController alloc] init];
    profileVC.view.backgroundColor = COLOR_RANDOM;
    [self addChildViewController:profileVC title:@"我" img:[UIImage imageNamed:@"tabbar_profile"] selectedImg:[UIImage imageNamed:@"tabbar_profile_selected"]];
    


}
-(void)addChildViewController:(UIViewController*)vc title:(NSString*)title img:(UIImage*)img selectedImg:(UIImage*)selectedImg{
    LBNavViewController *nav = [[LBNavViewController alloc] initWithRootViewController:vc];
    vc.title = title;
    vc.tabBarItem.image = img;
    vc.tabBarItem.selectedImage  = selectedImg;
    [self addChildViewController:nav];


}

-(void)tabBar:(LBTabBar *)tabBar didClickPlusBtn:(UIButton *)btn{
    [self presentViewController:[[LBNavViewController alloc] initWithRootViewController:[[ComposeViewController alloc] init]] animated:YES completion:nil];

}

-(void)setUpTabBar{

    LBTabBar *tabBar = [[LBTabBar alloc] init];
    self.mainTabBar = tabBar;
    self.mainTabBar.frame = self.tabBar.frame;
    self.mainTabBar.delegate = self;
    [self setValue:self.mainTabBar forKeyPath:@"tabBar"];
}










@end
